package com.xingkeduo.business.user.controller;

import com.xingkeduo.business.transformation.json.CraftsmanLoginHistoryJTO;
import com.xingkeduo.business.user.domain.CraftsmanDomain;
import com.xingkeduo.pojo.query.CraftsmanLoginHistoryQO;
import com.xingkeduo.util.pojo.base.BaseController;
import com.xingkeduo.util.pojo.domain.CredentialJTO;
import com.xingkeduo.util.tool.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 授权登录 接口
 *
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/3/15 19:19
 **/
@RestController
@RequestMapping("/login")
public class LoginController extends BaseController {

    @Autowired
    private CraftsmanDomain craftsmanDomain;

    /**
     * 登录接口
     *
     * @param params:
     * @return : java.lang.String
     * @author : gaozifeng
     * @date : 2019/3/18 21:05
     */
    @PostMapping("/authorize")
    public String login(@RequestBody String params) {
        returnUtil = new ReturnUtil();
        try {
            CraftsmanLoginHistoryQO craftsmanLoginHistoryQO = CraftsmanLoginHistoryJTO.createQueryForLogin(params);
            return returnUtil.getSuccess(CredentialJTO.toJson(craftsmanDomain.login(craftsmanLoginHistoryQO)));
        } catch (Throwable t) {
            return dealException(t, returnUtil);
        }
    }

}
